<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>  

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>쿠폰 등록</title>

<script type="text/javascript" src="./js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">

	$(function(){
		
		$('#confirmId').click(function(){
			var cou_uid = $('#cou_id').val();
			
			$.getJSON('cou_idCheck.do', {cou_id:cou_uid}, function(data){
				var result = data.result;
				if(result=='useOk'){
					$('#cou_idUseOk').html('사용 가능!').css('color','blue');
				}else if(result=='alreadyUse'){
					$('#cou_idUseOk').html('사용 불가!').css('color','red');
				}else{
					$('#cou_idUseOk').html('통신 오류!').css('color','red');
				}
			});
		});
		
	});
	

</script>

<style type="text/css">

	.inputForm{
		 margin-top: 10px;
	}
	body{
		background-color: #F3E0B6;
	}

</style>
</head>
<body>

	<form:form commandName="ACouponCommand" role="form" class="form-horizontal" 
				name="registerCouForm" id="registerCouForm" enctype="multipart/form-data" action="registerCou.do" method="post">
		<form:errors element="div"/>
				
			<div id="title" align="right">
				<font size=4><strong><spring:message code="coupon.register.title"/></strong></font>
			</div>
			
			<div style="margin-top: 5px">
				<label for="cou_id"><strong>쿠폰 아이디</strong></label>
				<form:input path="cou_id"/><br>
				<button type="button" class="btn btn-default" id="confirmId">ID 중복확인</button>
				<font size=2 color="red"><span id="cou_idUseOk"><form:errors path="cou_id"/></span></font>
			</div>
				
			<div class="inputForm">
				<label for="cou_name"><strong>쿠폰 이름</strong></label><br>
				<form:input path="cou_name"/><br>
				<font size=2 color="red"><form:errors path="cou_name"/></font>
			</div>

			<div class="inputForm">
				<label for="image"><strong>이미지</strong></label>
				<input type="file" id="file" name="file" value="파일 선택"><br>
				<font size=2 color="red"><form:errors path="file"/></font>
			</div>
			
			<div class="inputForm">
				<label for="count"><strong>수량</strong></label><br>
				<form:input path="count" class="form-control"/><br>
				<font size=2 color="red"><form:errors path="count"/></font>
			</div>
			
			<div class="inputForm">
				<label for="use_point"><strong>구매 단가</strong></label><br>
				<form:input path="use_point" class="form-control"/><br>
				<font size=2 color="red"><form:errors path="use_point"/></font>
			</div>
				
			<div class="inputForm">
				<input type="submit" class="btn btn-lg" value="쿠폰 등록" >&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="btn btn-lg" value="취소" onclick="self.close()">
			</div>
			
	</form:form>

</body>
</html>